package com.jt.ktdemo.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * @author: yukaihang
 * created on: 2020/3/27 1:28 PM
 * description:
 */
public class ScreenUtil {

    private ScreenUtil() {
    }

    private static final int DEFAULT_STATUS_HEIGHT = 25;

    /**
     * 获取屏幕宽度，单位为px
     * @param context 应用程序上下文
     * @return 屏幕宽度，单位px
     */
    public static int getScreenWidth(Context context) {
        return getDisplayMetrics(context).widthPixels;
    }

    /**
     * 获取屏幕高度，单位为px
     * @param context 应用程序上下文
     * @return 屏幕高度，单位px
     */
    public static int getScreenHeight(Context context) {
        return getDisplayMetrics(context).heightPixels;
    }

    /**
     * 获取DisplayMetrics对象
     * @param context 应用程序上下文
     */
    private static DisplayMetrics getDisplayMetrics(Context context) {
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics = new DisplayMetrics();
        assert manager != null;
        manager.getDefaultDisplay().getMetrics(metrics);
        return metrics;
    }

    /**
     * 获得状态栏的高度
     * @param context
     */
    public static int getStatusHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    /**
     * 是否是全面屏
     * @param context
     * @return
     */
    public static boolean isFullScreen(Context context) {
        return getStatusHeight(context) > DEFAULT_STATUS_HEIGHT;
    }
}
